﻿using KinonekoSoftware.JuXiaoYouDB.SubSystem.Categories;
using KinonekoSoftware.JuXiaoYouDB.Core;

namespace KinonekoSoftware.JuXiaoYouDB.SubSystem
{
    partial class GlossaryDB
    {
        private IEnumerable<InstanceType> _InstanceTypeCache;
        private int                       _VersionOfInstanceType;
        
        //-------------------------------------------------------------
        //
        //          Private Methods
        //
        //-------------------------------------------------------------
        private void InitializeInstanceTypes()
        {
            //
            // 添加所有
            _InstanceTypeCache = InstanceType.GenerateDefaultTypes();
            _InstanceTypeCollection.Insert(_InstanceTypeCache);
            
            //
            //
            _VersionOfInstanceType++;
        }
        
        //-------------------------------------------------------------
        //
        //          Public Methods
        //
        //-------------------------------------------------------------
        public IEnumerable<InstanceType> GetInstanceTypes()
        {
            if (!_HasInstanceTypeCollection)
            {
                InitializeInstanceTypes();
                _HasInstanceTypeCollection = true;
            }

            //
            //
            _InstanceTypeCache = _InstanceTypeCollection.FindAll();
            
            //
            //
            return _InstanceTypeCache;
        }
        
        
        public int CountOfInstanceType   => _InstanceTypeCollection.Count();
        public int VersionOfInstanceType => _VersionOfInstanceType;
    }
}